Repository navigation
fix(core): strip terminal escape sequences before output redaction - #1606
smart-ssh-coordinator[bot] merged 15 commits into
Conversation
…1605) Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
There was a problem hiding this comment.
Review
Verdict: changes requested
Review level: elevated
Blocking
-
crates/core/src/ai/terminal_escapes.rs:49-58(and the0x9Bhandling at:23-26,:36): this loosens redaction. Secrets the old redactor masked are now forwarded unmasked. A loneESCor a raw0x9Btakes the next printable character as the final byte of a "two-byte" sequence (or of a CSI), andstripremoves that character together with the ESC. If a secret starts right after that byte, it loses its first character and no pattern matches any more. The issue requires "fail-safe, never redact less than before". I checked these inputs in this session with a temporary probe againstredact_text/redact, comparing the baseredactor.rswith this PR:"x \x1bghp_abcdefghijklmnopqrstuvwxyz0123456789 y": basex \x1b[REDACTED] y, PRx hp_abcdefghijklmnopqrstuvwxyz0123456789 y"x \x1b ghp_…"(ESC + space as an intermediate byte, thengas the final byte): base masked, PRx hp_…"id \x1bAKIAIOSFODNN7EXAMPLE y": base masked, PRid KIAIOSFODNN7EXAMPLE y"\x1b-----BEGIN RSA PRIVATE KEY-----\n<body>\n-----END RSA PRIVATE KEY-----\n":-counts as an intermediate byte andBas the final byte, so the header becomesEGIN RSA PRIVATE KEY-----. The whole key body is forwarded in plaintext. The base masked it.- raw bytes
id \x9bAKIAIOSFODNN7EXAMPLE yviaredact(): baseid �[REDACTED] y, PRid KIAIOSFODNN7EXAMPLE y
One fix that keeps every requirement: apply the patterns to the lossy-decoded original first (exactly as before), then strip, then apply the patterns again to the stripped text. Every match from before is then still masked, and coloured secrets are caught too. Add these inputs as regression tests that compare against the old behaviour. With that ordering, also check that stripping cannot damage a
[REDACTED]marker that directly follows an ESC:ESC+[REDACTED]parses as CSI with final byteR. That only looks odd and does not leak, but it is worth a test. Afterwards, the PR body's "redaction only gets stricter" (threat-model note) must actually hold. -
crates/core/src/ai/terminal_escapes.rs:test_token_right_after_sgr_is_masked: this test has no counter-proof. It stays green whenredact_bytesgoes back to the oldfrom_utf8_lossyline: I reverted it and 6 tests failed, but not this one, because theghp_pattern also matches after[32m. The criterion "provider token directly after an SGR code → masked" therefore has no test that fails without the fix. Use a token or format whose pattern does not match on the raw coloured text (check this with the counter-proof).
Non-blocking
redact_textis also used for the command text in the execution log and in debug logs (action_exec/execute.rs:406/487,filter/engine.rs:300). A command containing raw ESC bytes is now logged without them. The issue intends this ("logs"). It is noted here only because the logged command can now differ from the executed bytes.
Verified
- counter-proof:
redact_bytesreverted toString::from_utf8_lossy→ 6 tests red (test_grep_color_password_value_is_masked,test_key_and_value_coloured_separately_is_masked,test_pem_header_with_sgr_masks_the_body,test_redact_output_strips_stdout_and_stderr,coloured_secret_is_still_redacted,live_redaction::test_coloured_secret_across_chunks_is_never_shown_nor_half_escape); restored → green.test_token_right_after_sgr_is_maskedstayed green, see Blocking (executed:cargo test -p ssh-manager-core --lib ai::) - adversarial bypass attempts: lone ESC before a token, ESC + space intermediate, ESC before an AWS key, ESC before a PEM header, raw
0x9Bbefore an AWS key → all 5 are a loosening compared with the base. SGR inside a value, OSC followed by an unterminated ESC beforepassword=, double ESC before a PEM header → ok (executed: temporary probe test against the base and the PRredactor.rs, removed afterwards,git statusclean) - edge cases: unterminated CSI/OSC at the end → removed (read + tests); line break inside an unterminated sequence → kept, so live line release stays intact (read:
skip_csi/skip_string); valid UTF-8 containing a0x9Bcontinuation byte → unchanged (test) - callers checked:
redact_bytes(2 call sites:redact,redact_text);redact_text(~25 files across app-logic/core/mcp/ai-providers: logs, notes, titles, attachments, injection reason) → behaviour change only as intended; see Non-blocking (read:rg -n 'redact_text\(') - tests run locally:
cargo test -q --locked -p ssh-manager-core --lib ai::→ 202 passed (executed) - CI: all checks green (executed:
gh pr checks 1606) - files read: 5/5 logic files (
terminal_escapes.rs,redactor.rs,live_redaction.rs,redactor_property.rs,mod.rs) - UI: not a UI change
- data: not touched
Timing analysis
- 3 test files analysed: no timing dependency found (synchronous, deterministic; the proptest has no time limit)
Spec
- visible behaviour changed: escape sequences are removed from the text forwarded to the AI, chat and logs; coloured secrets are masked
- spec searched (
rg -il 'escape|Escape-Sequenz|redact' docs/specs/), spec covering it: 0068 Part 1 - verdict: spec change present and matches the code. Once the loosening is fixed, check the sentence "Text ohne
ESCbleibt unverändert" again; it still holds.
Security checks
- Redaction invariant "never redact less than before": violated (see Blocking)
- Loosening check:
redact_bytesbefore (lossy → patterns) vs. after (lossy + strip → patterns). Strip removes printable characters after ESC/0x9B, with 5 concrete inputs above - Escape injection into the AI context: stopped for CSI/OSC/two-byte sequences (read)
- Live redaction: prefix and never-revise rules are unaffected, because a sequence never crosses a line break (read + test)
- Threat model: the note "no change – only gets stricter" does not hold yet
Follow-ups
None.
…nnot eat a secret's first char (#1605) Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
Review point 1 fixed in the latest commit: patterns now run on the original text, then escapes are stripped, then patterns run again; regression test |
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
#1605) Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
There was a problem hiding this comment.
Review
Verdict: changes requested
Review level: elevated
Blocking
-
crates/core/src/ai/terminal_escapes.rs:38-46(around_strip) together withredactor.rs:1411-1419: redaction is still looser than on the base, through the placeholder. The first pass now replaces a secret with[REDACTED]. Thenstripruns, and anESC(or a raw0x9B) directly in front of the placeholder is parsed as CSIESC [with final byteR, so[REDACTED]turns intoEDACTED].absorb_fragments_next_to_placeholdersonly runs after the second pass and looks for the intact[REDACTED]. It finds none and returns the text unchanged, so the rest of an over-long token is no longer absorbed. I compared these inputs in this session with a temporary probe againstredact_text, on the baseredactor.rsand on this PR:"id \x1bAKIAIOSFODNN7EXAMPLEtailsecret99 y": baseid \x1b[REDACTED] y, PRid EDACTED]tailsecret99 y(tailsecret99leaks)"x \u{9b}AKIAIOSFODNN7EXAMPLEtailsecret99 y": basex \u{9b}[REDACTED] y, PRx REDACTED]tailsecret99 y(leaks)"x \x1bghp_…0123456789EXTRAsecret y": PRx EDACTED] y. Nothing leaks here because theghp_pattern is open-ended, but the placeholder is still damaged.
Fixed-length patterns (
AKIA…{16}and similar) depend on absorption whenever the token is longer, for example anAKIAmatch inside a longer blob (the comment aboveabsorb_fragments_next_to_placeholders). Last round I asked for a test ofESC+[REDACTED], and it was not added. Possible fixes: run the absorption inside the first pass, beforestrip, and again at the end. In addition,stripmust not consume anESC/0x9Bfollowed by[REDACTED]as CSI; drop only the introducer, so the marker stays intact for the second pass and the final absorption. Add the inputs above as regression tests with exact expected output ([REDACTED]intact, no tail). Until this is fixed, the PR body's note "Threat model: no change – redaction only gets stricter" does not hold.
Non-blocking
- Carried over:
redact_textis also applied to logged command text, so a command with raw ESC bytes is logged without them (intended by the issue, "logs").
Verified
- counter-proof:
redactor.rsreverted toorigin/release/0.8.0→ 6 tests red (test_grep_color_password_value_is_masked,test_pem_header_with_sgr_masks_the_body,test_key_and_value_coloured_separately_is_masked,test_redact_output_strips_stdout_and_stderr,test_token_split_by_sgr_is_masked,coloured_secret_is_still_redacted). The rewritten token test now fails without the fix. Restored → green (executed:cargo test -q --locked -p ssh-manager-core --lib terminal_escapes, thengit checkout HEAD -- …,git statusclean) test_secret_right_after_lone_esc_or_c1_csi_is_maskedguards against the previous round's version, not against the base. It is green on the base as intended, but it checks only for the token's absence, not for an intact placeholder or an absorbed tail (read)- adversarial: lone ESC /
0x9Bbefore a fixed-length token with a trailing fragment → leak (see Blocking). SGR before an over-long AKIA (\x1b[32mAKIA…tail\x1b[0m) → masked. ESC beforepassword=/ URL credentials → masked, because the first pass already masked them and only a non-secret first character is eaten (executed: temporary probe test inredactor.rs, removed afterwards) - edge cases: unterminated CSI/OSC at the end, line break inside a sequence, valid UTF-8
0x9Bcontinuation byte → ok (read + tests) - callers checked:
redact_bytes(2 call sites:redact,redact_text),around_strip(1 call site),strip/strip_text(test-only / internal) → ok (read:rg -n) - tests run locally:
cargo test -q --locked -p ssh-manager-core --lib ai::→ 203 passed (executed) - CI: all checks green (executed:
gh pr checks 1606) - files read: 5/5 logic files (
terminal_escapes.rs,redactor.rs,live_redaction.rs,redactor_property.rs,mod.rs; full diff against the base) - UI: not a UI change
- data: not touched
Timing analysis
- 2 test files analysed (
terminal_escapes.rs,live_redaction.rs): no timing dependency found
Spec
- visible behaviour changed: escape sequences are removed from the forwarded text; coloured secrets are masked
- spec searched (
rg -il 'escape|Escape-Sequenz|ANSI|redact' docs/specs/), spec covering it: 0068 Part 1 - verdict: spec change present and matches the code
Security checks
- Redaction invariant "never redact less than before": still violated, via the damaged placeholder and the skipped absorption (see Blocking)
- Loosening check: base (lossy → patterns → absorb) vs. PR (lossy → patterns → strip → patterns → absorb).
stripbetween the two passes can destroy the marker that absorption depends on, shown with concrete inputs above - Escape injection into the AI context: stopped (read)
- Live redaction: prefix and never-revise rules unaffected, because a sequence never crosses a line break (read + test)
- Release branch: diff stays within the issue's scope
Previous findings (follow-up round only)
- lone ESC /
0x9Beats the first character of a secret → fixed in 21328e5 for the reported inputs. The new design opens the placeholder/absorption gap above (still open in another form) test_token_right_after_sgr_is_maskedwithout counter-proof → fixed in 21328e5 (test_token_split_by_sgr_is_maskedfails without the fix)
Follow-ups
None.
) Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ss (#1605) Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
Review point 1 fixed in the latest commits: the escape stripper now drops only the ESC/0x9B introducer when it directly precedes |
There was a problem hiding this comment.
Review
Verdict: needs maintainer
Review level: elevated
This is the third review round. The point from round 2 (escape stripping damages a [REDACTED] placeholder that the first pass inserted) is still open in another form. The process rules hand a third round on the same point to the maintainer.
Blocking
crates/core/src/ai/terminal_escapes.rs:39-47together withredactor.rs:1418(absorb_fragments_next_to_placeholdersinside the first pass): the most common coloured-secret case still loses the placeholder's[, and plain-text tail absorption does not happen.- The first pass runs on the raw text. Its absorb step eats the SGR parameter bytes in front of the placeholder:
\x1b[31m+[REDACTED]becomes\x1b[+[REDACTED]. - The new guard only handles
ESCimmediately followed by[REDACTED]. HereESC [is followed by[REDACTED], sostripreads the placeholder's[(0x5B) as the CSI final byte and leavesREDACTED]. - Pass 2 then finds no placeholder, so a fragment that only becomes adjacent after stripping is not absorbed.
- Confirmed by a temporary probe (reverted):
x \x1b[31mAKIAIOSFODNN7EXAMPLE\x1b[0m y→x REDACTED] yx \x1b[1;31mghp_…(36)\x1b[0m y→x REDACTED] y. This is exactly the AC 3 input shape (ESC[32m+ token +ESC[0m).x \x1b[31mAKIAIOSFODNN7EXAMPLE\x1b[1mtailsecret99\x1b[0m y→x REDACTED]tailsecret99 y. The same text without colours givesx [REDACTED] y.PREFIX\x1b[0mAKIA… y→PREFIXREDACTED] y
- On the base branch these give
x \x1b[[REDACTED]…, with the tail leaked as well. So this is not a loosening against the base, but it breaks:- The goal: coloured output is masked "just as it does in plain text".
- Spec 0068 Part 1: secrets are replaced by
[REDACTED]. - Callers that test for
REDACTED_PLACEHOLDER. For example,crates/app-logic/src/orchestration/notes.rs:173(T10) keeps a note proposal that consists only of a coloured secret, asREDACTED], instead of dropping it.
- No test checks the exact output for the AC 3 input.
test_token_split_by_sgr_is_maskedonly asserts that fragments are absent.
- The first pass runs on the raw text. Its absorb step eats the SGR parameter bytes in front of the placeholder:
Non-blocking
crates/app-logic/src/session/swappable.rs:106-145:mask_literals(known credential values) runs beforeDefaultOutputRedactor, on unstripped bytes. A literal secret with an SGR code in the middle (MYPA\x1b[0mSSWORD) stays unmasked, the same as on the base. This is outsideredact_bytesand outside the issue's list. Follow-up.
Verified
- counter-proof:
test_introducer_before_placeholder_keeps_placeholderandtest_introducer_before_secret_keeps_placeholder_and_absorbs_tailare red with the placeholder guard instrip_textremoved and green with it (executed: temporary edit,cargo test -p ssh-manager-core --lib introducer_before, reverted). With only the absorb-in-pass change reverted (redactor.rs from 248470b), both stay green; the guard alone carries them (executed). - edge cases: SGR with parameters in front of the token → finding (above); OSC with BEL in front of the token →
[REDACTED]ok;ESC (in front of the token →REDACTED](same finding); key/value coloured separately → ok (executed: temporary probe test, reverted) - base comparison of the finding inputs (executed: temporary base-redactor probe, reverted)
- callers checked:
REDACTED_PLACEHOLDERconsumers (notes.rs 3 sites, swappable.rs, tests) → finding at notes.rs:173;redact_bytescallers unchanged signature (read) - files read: 5/5 logic files (full diff of terminal_escapes.rs, redactor.rs, live_redaction.rs, redactor_property.rs, mod.rs)
- tests run locally:
cargo test -q -p ssh-manager-core --lib ai::→ 205 passed (executed) - CI: all checks pass (executed:
gh pr checks 1606) - UI: not a UI change
- data: not touched
Timing analysis
- 3 test files analysed: no timing dependency found (pure string tests; proptest with a per-run seed)
Spec
- visible behaviour changed: escape sequences are removed from redacted output; coloured secrets are masked
- spec searched (
rg -il 'escape|redact|schwärz' docs/specs/); the spec covering it is 0068 Part 1, updated in this PR - verdict: the spec change is present, but the code contradicts 0068 Part 1, which says secrets are replaced by
[REDACTED](finding above)
Security checks
- Redaction loosening against the base: the output is a subsequence of the base output plus extra masking. I found no input that the base masks and the PR leaks; the round 1 and round 2 inputs are fixed.
- 8 bypass attempts (SGR with parameters, 256-colour SGR, OSC/BEL,
ESC (, lone ESC, raw/encoded 0x9B, literalESC[31[REDACTED], coloured tail after a token): no leak against the base. The placeholder is damaged as described. - Threat model note: "redaction only gets stricter" holds against the base.
Previous findings
- lone ESC eats the first character of a secret → fixed (21328e5)
- token test without counter-proof → fixed
- ESC/0x9B directly before a placeholder eats
[, tail not absorbed → fixed for that exact form (c328459, e83383a); still open when SGR parameters are in between (above)
Follow-ups
- Literal credential masking (
SwappableRedactor::mask_literals) does not see secrets split by escape sequences (no existing issue)
|
Review point 1 (ESC/0x9B before a placeholder eating |
There was a problem hiding this comment.
Review
Verdict: changes requested
Review level: elevated
The head (e83383a5) is the same commit as in the previous review round. The maintainer has since decided the open question on the issue: option 2. Strip the escape sequences first, then run the patterns and fragment absorption once on the stripped text. There is no second pass. A lone ESC/0x9B is dropped on its own and never consumes the following character. That decision is not implemented yet.
Blocking
crates/core/src/ai/terminal_escapes.rs:39-47(around_strip) andcrates/core/src/ai/redactor.rs:1411-1421: the two-pass design is still in place: apply, strip, apply again. The maintainer's acceptance says "the two-pass code is removed, not kept beside the new flow". Required: inredact_bytes, decode and strip, then run the patterns andabsorb_fragments_next_to_placeholdersonce.crates/core/src/ai/terminal_escapes.rs:83-85(Some(n) if ('\u{30}'..='\u{7E}')branch) and the testtest_lone_esc_and_two_byte_sequences_are_removed(strip(b"a\x1bb") == "a"):ESCfollowed by any printable character in0x30–0x7Estill eats that character. Executed:"a\x1bbcd"→"acd". The decision requires that a loneESC/0x9Bis dropped without consuming the next character. This is also what made the second pass necessary in the first place (round 1:\x1bAKIA…). Restrict the two-byte form to real escape finals, or drop the introducer alone, and update the test. Keep the round-1 inputs (ESC/0x9Bbeforeghp_…,AKIA…, the PEM header) as regression tests on the new single-pass flow.- The placeholder is still damaged (executed with a temporary probe test on this head, since reverted):
"x \x1b[31mAKIAIOSFODNN7EXAMPLE\x1b[0m y"→"x REDACTED] y". Expected exactly"x [REDACTED] y"."x \x1b[31mAKIAIOSFODNN7EXAMPLE\x1b[1mtailsecret99 y"→"x REDACTED]tailsecret99 y". Plain text gives"x [REDACTED] y", so the coloured tail stays visible.- This contradicts the goal ("just as it does in plain text") and Spec 0068 ("replaced by
[REDACTED]").
- Missing tests that the maintainer's acceptance requires:
- exact-output tests for the two inputs above;
- a property test showing that, for every secret generator,
redact(SGR-wrapped text) == redact(plain text). The currentcoloured_secret_is_still_redactedonly checks that no secret substring remains, so it would not catch theREDACTED]damage.
- PR body: the "Assumptions" and "Summary" sections still describe the old flow, and "Threat model: no change – redaction only gets stricter" has to be true of the new flow. Update the body once the code changes.
Non-blocking
- None.
Verified
- counter-proof: not repeated this round. The head is unchanged, and the blocking issue is a mismatch with the maintainer's decision, shown with the probe inputs above (executed: temporary
reviewer_probetest interminal_escapes.rs,cargo test -p ssh-manager-core --lib reviewer_probe, thengit checkout --). - files read: 5/5 logic files (
redactor.rs,terminal_escapes.rs,live_redaction.rs,redactor_property.rs,mod.rs) (read: full diff). - edge cases: SGR with parameters before a token → finding; coloured tail after a token → finding; lone
ESCbefore a printable character → finding (consumes it); plain text withoutESC→ unchanged (read:strip_textearly return). - callers checked:
redact_bytes(redact,redact_text, live redaction throughredact_text) → all go through the one function, so the fix in one place reaches every caller (read). - tests run locally:
cargo test -q --locked -p ssh-manager-core --lib ai::→ 205 passed (executed). - UI: not a UI change.
- data: not touched.
- CI: all checks green (executed:
gh pr checks 1606).
Timing analysis
- 2 test files analysed (
terminal_escapes.rs,live_redaction.rs;redactor_property.rsonly changes a doc comment): no timing dependency found. The tests are pure, synchronous string processing.
Spec
- visible behaviour changed: escape sequences are removed from redacted output, and secrets in coloured output are masked.
- spec searched (
rg -il 'escape|redact|ANSI' docs/specs/), spec covering it: 0068 Part 1. - verdict: a spec change is present. Once the single-pass flow lands, re-check it against the code, in particular the lone-
ESCrule ("a singleESC" is removed, not the following character).
Security checks
- Redaction: the single-pass flow has to be no looser than the base for the round-1 and round-2 inputs; keep them as regression tests. No other invariants are touched (no filter, credentials or execution path).
- Threat model: the note depends on the redaction actually being at least as strict; re-check it after the rewrite.
Manual checks pending
- None.
Previous findings
- First character eaten after a lone ESC (round 1) → worked around by the second pass, which the maintainer has now ruled out; still open in the new form (see Blocking).
- Placeholder damage from SGR parameters (round 3) → still open; the maintainer chose option 2.
Follow-ups
- None.
…m eating characters (#1605) Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
Review points fixed in 097210e: (1) two-pass flow and |
There was a problem hiding this comment.
Review
Verdict: needs maintainer
Review level: elevated (issue label security; files under crates/core/src/ai/)
Blocking
-
crates/core/src/ai/redactor.rs:1413together withcrates/core/src/ai/terminal_escapes.rs(strip_str): redaction is looser than on the base branch when a removed sequence sits between a word character and a token. Removing the sequence joins the two sides. Patterns anchored with a leading\b(gsk_,xai-,hf_,SK…,SG.,eyJ…JWT,api-key,authorization, …) then no longer match. On the base branch the ESC, BEL or non-word final byte acted as the boundary. Compared on the same build (executed, base vs. PR):x\x1bgsk_abcdefghijklmnopqrstuvwxyz0123456789AB y→ basex\x1b[REDACTED] y, PRxgsk_abcdefghijklmnopqrstuvwxyz0123456789AB yx\x9bgsk_…(8-bit introducer) → base masked, PR plaintextx\x1b[2~gsk_…(CSI with final~) → base masked, PR plaintextx\x1b]0;t\x07gsk_…(OSC/BEL) andid\x1b]8;;file:///a\x1b\\gsk_…(OSC 8 hyperlink/ST) → base masked, PR plaintextx\x1b[@eyJ….eyJ….…andx\x1beyJ…(JWT) → base masked, PR plaintextmy\x1b[2~api-key: supersecret123 y→ base masked, PRmyapi-key: supersecret123 y
The issue's Technical Notes say "never redact less than before". The PR's threat-model note ("redaction only gets stricter") does not hold for these inputs. The loss comes straight from the decided design: strip first, a single pass, and a lone
ESC/0x9Bdropped on its own. A fix would need either a separator in place of some removed sequences (so the text is not purely "removed") or a second match. The maintainer ruled out a second match. So this goes back to the maintainer instead of to the coder.
Non-blocking
- None.
Verified
- files read: 5/5 logic files (
redactor.rs,terminal_escapes.rs,live_redaction.rs,redactor_property.rs,mod.rs), full diff (read) - the earlier findings and the maintainer decision (option 2) are implemented: single pass
decode → strip → patterns → absorb, two-pass code removed,a\x1bbcd→abcd, exact-output tests forx \x1b[31mAKIA…\x1b[0m y→x [REDACTED] yand for the coloured tail, propertysgr_wrapped_equals_plain(read:terminal_escapes.rs) - counter-proof: with the old
from_utf8_lossyline restored inredact_bytes, 9 of the new tests fail (grep colour, PEM header, token split by SGR, key/value coloured, exact placeholder, coloured tail, introducer before secret, stdout/stderr, live chunks). With the fix back, all pass.test_secret_right_after_lone_esc_or_c1_csi_is_maskedstays green either way, as intended, because it is a no-regression guard for round 1 (executed:cargo test -p ssh-manager-core --lib -- terminal_escapes::tests::test_ live_redaction::tests::test_coloured) - base vs. PR comparison of the inputs above (executed: a temporary probe test in a base worktree and in the PR checkout, both reverted;
git statusclean) - edge cases: unterminated CSI/OSC at the end → removed (read and tested); sequence split across live chunks → never released half (executed, live test over every chunk size); line breaks never swallowed → ok (read); word character + removed sequence +
\b-anchored token → finding (above) - callers checked:
redact_bytes(3 call sites:redactstdout/stderr,redact_text) → ok.LiveOutputRedactorgoes throughredact_text→ ok. Frozenredactor_reference.rsunchanged (read) - tests run locally:
cargo test -q --locked -p ssh-manager-core --lib ai::→ 207 passed (executed) - CI: all checks green on
097210e3(executed:gh pr checks 1606) - UI: not a UI change
- data: not touched
Timing analysis
- 2 test files analysed (
terminal_escapes.rs,live_redaction.rs). The two proptests with 300 cases took about 125 s locally, flagged "likely" for CI timeouts. Dismissed: no clock or wait dependency. The nextestciprofile terminates only after 3 × 120 s, the case count matches the existingredactor_property, and CI passed on all three OSes. The chunk loop in the live test is cheap and deterministic.
Spec
- visible behaviour changed: escape sequences are removed from text forwarded to the AI, chat and logs; coloured secrets are masked
- spec searched (
rg -il 'escape|redact' docs/specs/), spec covering it: 0068 Part 1 - verdict: spec change present and matches the code (one new rule in Part 1). Changelog fragment present (English, Security)
Security checks
- Redaction still runs before content reaches the AI, chat or logs, in one place (
redact_bytes). No fail-open. The two-pass code is fully removed. - Loosening check against the base: a lone ESC no longer eats the next character (fixed), and the placeholder is not damaged (fixed). New loss at word boundaries (blocking, above).
- Bypass attempts: lone ESC, raw/encoded
0x9B, CSI with non-word final byte (~,@), OSC with BEL and with ST, OSC 8 hyperlink, SGR between token halves, SGR between key and value, PEM header with SGR. The first five leak when a word character directly precedes; the rest are masked. - Threat model: the PR body's
no changereason ("only gets stricter") is contradicted by the finding above.
Follow-ups
- None.
|
Review points addressed in 097210e: (1) two-pass flow removed, single decode/strip/pattern/absorb pass; (2) lone ESC/0x9B dropped without consuming the next char, test updated, round-1 inputs kept as regression tests; (3) exact-output tests for placeholder and coloured tail added; (4) property test sgr_wrapped_equals_plain added; (5) PR body updated. CI green. |
There was a problem hiding this comment.
Review
Verdict: changes requested
Review level: elevated
The head (097210e3) is the same commit I reviewed at 08:57. The maintainer has since decided on option 1 (issue comment 08:59): a removed sequence that ends in a non-word character becomes one space, and SGR/erase codes (m/K) are still removed without a trace. That is not implemented yet, so this is a full round against that decision.
Blocking
-
crates/core/src/ai/terminal_escapes.rsstrip_str/skip_csi/skip_string: the decided option-1 rule is missing, and it is a loosening compared with the base branch. Every removed sequence is deleted without a trace, so the word on its left joins the token and patterns that start with a word boundary stop matching. Executed on the head throughDefaultOutputRedactor::redact_text, each of these returns the secret in plaintext (the base branch masks all of them, as confirmed in the previous round):x\x1bgsk_… y→xgsk_… yx\u{9b}gsk_… y→xgsk_… yx\x1b[2~gsk_… y→xgsk_… yx\x1b]0;t\x07gsk_… y→xgsk_… yx\x1b]8;;http://h\x1b\\gsk_… y(OSC 8 with ST) →xgsk_… yx\x1b[@eyJ….eyJ….sig y(JWT) →xeyJ… ymy\x1b[2~api-key: supersecret123→myapi-key: supersecret123
Fix as decided: replace a lone
ESC/0x9B, a BEL/ST-terminated string (OSC, OSC 8, DCS, …) and a CSI with a non-letter final byte (~,@, …) with one space. Remove SGR/erase (m/K) without a trace. Then decide for other letter-final CSIs and two-byteESCsequences, and document the choice. If unsure, use a space wherever the final byte is notm/K. -
Missing acceptance tests from the decision:
- exact-output tests for each of the seven inputs above;
- a property test: wrapping or prefixing secrets from every generator with arbitrary escape sequences (not only SGR: lone ESC, raw/encoded
0x9B, CSI~/@, OSC with BEL, OSC 8 with ST) never leaves a secret substring that the frozen reference redactor (redactor_reference.rs) masks in the same input.
sgr_wrapped_equals_plainandtest_sgr_around_secret_leaves_exact_placeholdermust keep passing. -
crates/core/src/ai/terminal_escapes.rs:178-202test_lone_esc_and_two_byte_sequences_are_removed: the expectationsa\x1bbcd → abcdand the bare-0x9Brule conflict with the decision, which says a lone introducer becomes a space. Update them to match. -
docs/specs/0068-security-hardening-prelaunch.mdPart 1: the new paragraph says sequences are removed. It must also state the decided rule: non-colour sequences and a loneESCbecome one space, colour/erase codes leave no trace. Without that, the spec does not describe the behaviour once the fix is in. -
PR body: "Assumptions" (lone ESC "dropped alone") and
Threat model: no change – redaction only gets stricterare both untrue for the current head. Rewrite them for the option-1 flow. The threat-model note may only claim "only stricter" once the inputs above are covered by tests. -
crates/core/src/ai/terminal_escapes.rs:186-188(red()), used by the proptests at:291-331: timing (confirmed). Every call builds a newDefaultOutputRedactor, which recompiles all pattern regexes, about 600 times per proptest run. Locallysgr_wrapped_equals_plainalone ran for over 60 s. The nextest CI profile stops a test at 3 × 120 s, and the new escape property test will add the same cost again. Build the redactor once (for examplestatic RED: LazyLock<DefaultOutputRedactor>, or one instance shared by the tests), then keep or lower the case count.
Non-blocking
- An ADR recording the stripping rules (SGR without a trace, other sequences become a space, CSI/OSC never swallow
\n/\r) would help later changes. The decision currently lives only in the issue.
Verified
- files read: 5/5 logic files (
terminal_escapes.rs,redactor.rs,live_redaction.rs,redactor_property.rs,mod.rs) (read: full diff againstorigin/release/0.8.0) - counter-proof: not repeated this round. The head is unchanged, and the counter-proof from the previous round stands. The open finding is a missing rule, not a test without meaning.
- edge cases: the seven word-boundary inputs from the decision → finding, all leak (executed: temporary probe test in
terminal_escapes.rsrunningredact_text, reverted withgit checkout;git statusis clean). SGR around a token → exactx [REDACTED] y(read: test). A coloured tail is absorbed (read: test). - callers checked:
redact_bytes(redact,redact_text, live redaction, diagnostics all go through it) → ok, one place (read:redactor.rs) - tests run locally:
cargo test -q --locked -p ssh-manager-core --lib ai::→ 207 passed (executed) - CI: all checks green (executed:
gh pr checks 1606) - UI: not a UI change
- data: not touched
Timing analysis
- 2 test files analysed (plus a doc-only change in
redactor_property.rs). terminal_escapes.rs:186-188: redactor rebuilt on everyred()call inside proptests with 300 cases. Likely, confirmed by local runtime (>60 s for one proptest) → blocking (see above).terminal_escapes.rs:291: fixed 300 cases with heavy regex inputs. Possible → non-blocking once the redactor is shared.live_redaction.rs:331-342: about 50live_viewcalls. Possible, cost only, no race → non-blocking.
Spec
- visible behaviour changed: escape sequences are removed from the output forwarded to the AI, chat and logs; per the decision, non-colour sequences become one space.
- spec searched (
rg -il 'escape|ESC\[|Farbcode|redact' docs/specs/), spec covering it: 0068 Part 1 (redaction rules) - verdict: spec change present, but incomplete for the decided rule (blocking, update 0068)
Security checks
- Redaction (elevated): compared
redact_bytesbefore and after. The single-pass strip-then-match flow works for SGR. Deleting non-SGR sequences without a trace is a loosening, with the concrete inputs listed above (bypass attempts: lone ESC, raw C1 CSI, CSI~/@, OSC BEL, OSC 8 ST, JWT,api-keyafter a word character). - Fail-open / swallowed errors: none found. Invalid UTF-8 still becomes U+FFFD, and a raw
0x9Bis kept distinguishable from it. - No change to the filter, AutoExec/Confirm, credentials or host keys.
- Threat model: the PR-body note is not valid while the loosening exists (see Blocking).
Manual checks pending
- None.
Previous findings
- Round 4 (two-pass removal, lone ESC eating a character, exact placeholder, SGR property test, PR body) → fixed in
097210e3. - Round 5 (word-boundary loss, escalated to the maintainer) → decided as option 1, still open.
Follow-ups
- None.
…test (#1605) Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
Review points 1–6 fixed in the latest commit (space rule in terminal_escapes, exact-output + property tests, lone-ESC test updated, spec 0068 updated, PR body rewritten, redactors built once via LazyLock). |
There was a problem hiding this comment.
Review
Verdict: changes requested
Review level: elevated
Blocking
-
crates/core/src/ai/terminal_escapes.rs:53-85(space rule) +redactor.rs:1411-1420— this redacts less than the base branch when a non-SGR escape sits inside a secret value. The inserted space ends the value before the pattern sees the rest. I ran these against the PR and the frozen reference redactor (the base redactor is property-tested to be at least as strict as the reference):password=hun\x1b[2~ter2secret→ PR[REDACTED] ter2secret, reference[REDACTED]token: abcd\x1b]0;t\x07efghsecretvalue→ PR[REDACTED] efghsecretvalue, reference[REDACTED]https://user:\x1b[2~hunter2pass@host/x→ PRhttps://user: hunter2pass@host/x, referencehttps://user:[REDACTED]@host/x- proptest shrink (secret wrapped with escapes, every generator):
https://aaa:\x1baaaaaaaa\x1bP1$r\x1b\\@example.com/path→ PRhttps://aaa: aaaaaaaa @example.com/path, reference masks it.
The maintainer's decision says "never redact less than before" wins. It also adds the acceptance criterion: "wrapping or prefixing secrets from every generator with arbitrary escape sequences never leaves a secret substring that the frozen reference redactor masks".
any_escape_never_leaks_what_reference_masksonly puts escapes before and after the whole snippet, not around each secret. The PR body admits this narrowing under Assumptions and Follow-ups. A narrowed acceptance criterion cannot be a follow-up. Suggested fix, which keeps the decided user-visible rule: while matching, replace each non-SGR sequence with a private sentinel character that is not a word character and not whitespace (for example U+E000). Then\bstill holds in front ofgsk_/eyJ/api-key, and value classes such as[^\s…]still span it. Run the patterns and absorption once, then turn any remaining sentinels into one space. Check that the sentinel cannot occur in the input (or map an existing one to U+FFFD first). Also check that absorption and the value classes treat it as part of a value. Then make the property test wrap each secret insnip.secrets({a}{secret}{c}, any escape), as the criterion says. -
crates/core/src/ai/terminal_escapes.rs:215-234test_non_sgr_escapes_before_secrets_do_not_leak— the maintainer asked for exact-output tests for the seven review inputs. The test only checks that three needles are absent. Assert the full expected string for each input, as the SGR tests do. For example, todayx\x1bgsk_… ygivesx [REDACTED] yandmy\x1b[2~api-key: supersecret123givesmy [REDACTED]. Add the leaking inputs above as exact-output regression tests as well.
Non-blocking
- The PR body's Follow-ups entry ("non-SGR escapes inside a space-free token split it") becomes obsolete once the first finding is fixed. Remove it, and update Assumptions to match.
Verified
- counter-proof: I put the 097210e scanner back in place of the current one and kept the new tests. 6 tests fail (
test_non_sgr_escapes_before_secrets_do_not_leak,test_lone_esc_and_two_byte_sequences_are_removed,test_osc_with_bel_and_st_is_removed,test_introducer_before_secret_keeps_placeholder_and_absorbs_tail, two unterminated-sequence tests). After restoring the file they pass.any_escape_never_leaks_what_reference_masksstayed green against the old scanner, which shows it is too weak (see the first finding) (executed:cargo test -p ssh-manager-core --lib terminal_escapes) - the two-pass code is removed;
redact_bytesdoes decode → strip → patterns → absorb once (read:crates/core/src/ai/redactor.rs,terminal_escapes.rs) - edge cases: escape before a secret (7 review inputs) → masked; escape inside a value / URL userinfo → finding; SGR around a secret → exactly
x [REDACTED] y; plain text → unchanged; unterminated sequence before\n→ line break kept (executed: temporary probe test, since reverted,git statusclean) - callers checked:
redact_bytes(redact,redact_text;LiveOutputRedactorand diagnostics go through them) → strip happens in one place (read) - tests run locally:
cargo test -q --locked -p ssh-manager-core --lib ai::→ 209 passed (executed) - CI: all checks green on fa430d4 (executed:
gh pr checks 1606) - files read: 5/5 logic files (whole PR diff;
terminal_escapes.rsin full) - UI: not a UI change
- data: not touched
Timing analysis
- 2 test files analysed (terminal_escapes.rs tests and proptests, live_redaction.rs new test): no timing dependency found. The statics are read-only
LazyLocks and the proptests use a fixed case count.
Spec
- visible behaviour changed: escape sequences are removed from forwarded output; non-SGR sequences become one space
- spec searched (
rg -il 'escape|redact|ESC\[' docs/specs/), spec covering it: 0068 Part 1 - verdict: the spec change is present and matches the code. After the sentinel fix, the sentence "durch genau ein Leerzeichen ersetzt, damit sie Schlüssel und Wert weiterhin trennt" ("replaced by exactly one space so that it still separates key and value") stays true for the forwarded text. If the fix also changes how a value spanning such a sequence is masked, add that.
Security checks
- Redaction runs before forwarding (AI, chat, logs, live). Strip in one place.
- Loosening check against base and reference: a non-SGR escape inside a value splits it → loosening (blocking, see above). Before a token: fixed.
- Bypass attempts: lone ESC, raw/encoded 0x9B,
ESC[2~,ESC[@, OSC with BEL, OSC 8 with ST, DCS,ESC(B, inside a key=value value, inside URL userinfo, inside a Bearer token. - Threat-model note: "redaction only gets stricter"-style claims do not hold until the first finding is fixed.
Manual checks pending
- none
Previous findings (follow-up round only)
- Space rule (lone ESC/0x9B, OSC/ST, non-letter CSI → one space; SGR/erase without a trace) → implemented in fa430d4
- Exact-output tests for the seven inputs → still open (only absence asserted)
- Property test with arbitrary escapes vs. the reference → narrowed, still open
test_lone_esc_and_two_byte_sequences_are_removedupdated → fixed- Spec 0068 space rule → fixed
- PR body Assumptions/threat-model note → updated, but they describe the narrowing
- Timing (
LazyLockredactors) → fixed
Follow-ups
None.
…tinel (#1605) Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… redactor.rs within its size limit (#1605) Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
Review point 1: fixed in 214f985 (non-SGR sequences become a private-use sentinel during matching, so escapes inside a value no longer end it; leftovers become one space afterwards; regression tests plus the property now wrap every secret). Review point 2: fixed in the same commit (exact-output assertions for all seven inputs). PR body updated. Follow-up commit only moves helpers to keep redactor.rs within its size limit. |
There was a problem hiding this comment.
Review
Verdict: needs maintainer
Review level: elevated
Blocking
-
crates/core/src/ai/terminal_escapes.rs:85-105,128-142— redaction is still looser than the frozen reference when an escape sequence is incomplete and the next character is the first character of a secret. The scanner takes the secret's first character as the sequence's final byte. This is the same class as the round-1 finding (lone ESC eats the first character), now through CSI and nF sequences. Executed, PR vs. frozen reference (redactor_reference.rs) on the same input:x\x1b ghp_<36>→ PRx hp_<36> y(token in plaintext), referencex\x1b [REDACTED] yx\x1b(ghp_<36>→ PRx hp_…, reference[REDACTED]x \x1b(AKIAIOSFODNN7EXAMPLE→ PRKIAIOSFODNN7EXAMPLE, reference[REDACTED]x \x1b[AKIAIOSFODNN7EXAMPLE→ PRKIAIOSFODNN7EXAMPLE, reference[REDACTED]x\x1b[ghp_<36>→ PRhp_…, reference[REDACTED]\x1b[31;password=hunter2secret,\x1b[ password=…,\u{9b} password=…→ PRassword=hunter2secret, reference[REDACTED]
any_escape_never_leaks_what_reference_maskscovers only complete sequences, and itsprop_assumeexcludes snippets that start with[, so it does not catch this. Some of these inputs are ambiguous.\x1b[Ais a real cursor-up, so in\x1b[AKIA…theAis the final byte to a terminal. A single pass over stripped text cannot both treat that character as the final byte and still match the secret that starts with it. The two maintainer decisions in this issue conflict here: strip first, then one pass with the two-pass code removed, versus "never redact less than before" and the property criterion "never leaves a secret that the reference masks in the same input". Only the maintainer can resolve this, see the question in the issue. -
crates/core/src/ai/terminal_escapes.rs:57-59withredactor.rsredact_bytes—restore_separatorsalways runs. A literal U+E000 in output without any ESC therefore turns into a space:eza \u{E000} file→eza file. Nerd-Font icon output (e.g.eza --icons) uses U+E000. This breaks the acceptance criterion "Plain text withoutESCis byte-for-byte unchanged", and no test covers it. A literal U+E000 next to an escape gets the same treatment. The coder can fix this without a decision: run the restore only when stripping inserted sentinels, and pick a sentinel that cannot collide with input or escape the input's own U+E000. Add an exact-output test.
Non-blocking
terminal_escapes.rs:24-35decodepushes one U+FFFD per invalid byte. The baseString::from_utf8_lossypushes one per invalid sequence:a\xE2\x82b→ basea�b, PRa��b. This does not weaken redaction, but it changes the text for non-UTF-8 output without ESC. The comment says "as before", which is not quite true.live_redaction.rslive_viewbuilds a newDefaultOutputRedactoron every call (about 100 per new test). This is fast enough, but it could share theLazyLocklike the other tests.
Verified
- files read: 5/5 logic files (
terminal_escapes.rsin full,redactor.rs,live_redaction.rs,mod.rsandredactor_property.rsdiffs) (read) - counter-proof: with
redactor.rs/terminal_escapes.rsfrom fa430d4 (before the sentinel),test_non_sgr_escape_inside_secret_value_does_not_cut_itis red ([REDACTED] ter2secret). With HEAD it is green (executed:cargo test -p ssh-manager-core --lib test_non_sgr_escape_inside_secret_value_does_not_cut_it) - previous round's inputs (escape inside a value, seven leaking inputs with exact output) → fixed (executed via the tests above)
- edge cases: incomplete CSI/nF before a secret → finding; U+E000 in plain text → finding; invalid UTF-8 → non-blocking; escape inside a value → ok; SGR with parameters around a token → ok (executed: temporary probe test against the reference, reverted,
git statusclean) - callers checked:
redact_bytes(redact,redact_text, live redactor throughredact_text) → single place, ok (read) - tests run locally:
cargo test --locked -p ssh-manager-core --lib ai::→ 210 passed (executed) - CI: all checks green on 8e2b8d5 (executed:
gh pr checks 1606) - UI: not a UI change
- data: not touched
Timing analysis
- 3 test files analysed. No likely timing dependency. The proptests share
LazyLockredactors (terminal_escapes.rs:230,237), so they run well under the slow-timeout. Possible:live_viewrebuilds the redactor per call (non-blocking, see above).
Spec
- visible behaviour changed: escape sequences are removed from forwarded text; non-SGR sequences become one space; secrets in coloured output are masked
- spec searched (
rg -il 'escape|ANSI|REDACTED|Farb' docs/specs/), spec covering it: 0068 Part 1 - verdict: the spec change is present and matches the code for complete sequences. Its sentence "Text ohne
ESCbleibt unverändert" is contradicted by the U+E000 finding.
Security checks
- Redaction invariant "never less than before": compared against the frozen reference on the same inputs. Loosening confirmed for incomplete CSI/nF/C1 introducers before secrets (concrete inputs above).
- Bypass attempts: lone ESC, ESC SP, ESC
(,ESC[without params,ESC[31;, raw/encoded 0x9B, OSC/ST, escape inside the value, U+E000 injection. Results as listed above. - No new data flow or boundary. The threat-model note ("only normalisation") is acceptable once the loosening is resolved.
Previous findings (follow-up round only)
- non-SGR escape inside a secret value cuts it → fixed in 214f985
- seven inputs need exact-output tests → fixed in 214f985
- PR body update → done
Follow-ups
- None.
…tinel (#1605) Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…capes (#1605) Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
There was a problem hiding this comment.
Review
Verdict: changes requested
Review level: elevated
This is a follow-up round on the delta since 8e2b8d5 (ae4f32b, 7a2a34f). The union design rebuilds the core of the escape path, so I reviewed terminal_escapes.rs and its call site in full.
Blocking
crates/core/src/ai/terminal_escapes.rs:29-40(decode): input without ESC no longer matches the base byte for byte.String::from_utf8_lossy(base, and the frozen reference) writes one U+FFFD for each invalid sequence.decodewrites one U+FFFD for each invalid byte. A multi-byte character cut off at the size cap is a realistic case. Executed withredacton stdoutabc\xE2\x82 password=hunter2secret \xF0\x9F\x98: the PR gives"abc�� [REDACTED] ���", the reference gives"abc� [REDACTED] �". This breaks the maintainer's fast-path rule ("Input without ESC/0x9B: fast path, exactly the current redaction, byte-for-byte") and the AC "Plain text without ESC is byte-for-byte unchanged". The doc comment ("invalid bytes become U+FFFD, as before") is also wrong. Fix: push one U+FFFD per non-emptychunk.invalid(), and keep the special case for a lone0x9B. Add a regression test that compares the PR's output withString::from_utf8_lossyand with the reference on truncated UTF-8 input that has no ESC. (I found no input where the extra U+FFFD masks less. Not proven, so treat that part as unsure.)crates/core/src/ai/terminal_escapes.rs:435-459(test_incomplete_sequence_before_secret_leaks_nothing): the maintainer asked for exact-output tests for the eight inputs. Seven of them only check a partial needle. For example,x \x1b[AKIA…checks onlyIOSFODNN7, so a leakedEXAMPLEwould pass. Theghp_cases check onlyabcdefghijkl, so a leakedmnopqrstuvwxyz0123456789would pass. Onlyx\x1b ghp_…is asserted exactly. Assert the full output for all eight inputs, as was already done for the seven inputs of the previous round. The current outputs, all fully masked, are:[REDACTED],[REDACTED],x [REDACTED],x [REDACTED],[REDACTED],[REDACTED],[REDACTED],[REDACTED].crates/core/src/ai/terminal_escapes.rs:571-587(any_escape_never_leaks_what_reference_masks): the property is narrower than the maintainer's criterion ("arbitrary escape sequences inserted anywhere"). It puts one fixed paira/caround every secret and around the whole text. It never inserts at random positions, such as inside a value, between a key and its separator, or inside a PEM header. The PR body says it "inserts incomplete sequences anywhere", which is not true. I ran a temporary probe property (removed again) that inserts 1–3 escapes from an extended set (includingESC[AandESC[01;31m) at random char boundaries. It compares against secrets that occur literally in the input and that the reference masks. It passed 3,000 cases, so the behaviour looks right, but the PR has no test for it. Add such a property: random positions, filtered to secrets that occur literally in the input, so that an escape inside a secret does not count as "masked by the reference". Then correct the PR body. It namestest_token_right_after_sgr_is_masked, which no longer exists (it is nowtest_token_split_by_sgr_is_masked). The Summary still says the escapes are stripped "before any pattern runs". The threat-model note describes only the space rule, not the union of the raw and stripped views.
Non-blocking
- The escape path builds two
Vec<(usize, usize)>plus aVec<bool>per byte, and runscaptures_itertwice for every rule (intrack). That is roughly 40 bytes of bookkeeping per output byte, and only for output that contains an escape. This is acceptable at the current output cap; it is noted in case the cap grows. - Masking reaches a bit further than before. In
x\x1b ghp_…the leadingxis absorbed, so the output is[REDACTED]. This is more masking, not less, and follows from the decided design.
Verified
- counter-proof: with the union disabled (the
extramask forced to false inredact_escaped),test_incomplete_sequence_before_secret_leaks_nothing,test_non_sgr_escape_inside_secret_value_does_not_cut_itandany_escape_never_leaks_what_reference_masksfail; after restoring the code all 23 pass (executed:cargo test -p ssh-manager-core --lib terminal_escapes; the clone was reverted withgit checkout --, andgit statusis clean) - edge cases: the eight incomplete-sequence inputs → fully masked (executed, temporary probe); an escape inside a value (
ghp_abc\x1b[2~def…) → not masked, and the reference does not mask it either → ok; random escape insertion at 1–3 positions, 3,000 cases → no secret leaks that the reference masks (executed, temporary probe); truncated UTF-8 without ESC → finding 1; U+E000 without ESC → unchanged (executed:test_private_use_characters_without_escape_are_unchanged); a line break is never swallowed → ok (read:skip_csi/skip_string, tests) - live redaction:
LiveOutputRedactorcallsredact_texton lossy-decoded whole lines, and releases text only if the redaction of those lines is a prefix of the redaction of everything received so far. The union cannot break that guarantee, because both sides come from the same function (read:live_redaction.rs, executed: its tests) - callers checked:
redact_decoded(1 call site,redact_bytes), soredact,redact_text, live output and diagnostics all go through the same path → ok;redact_escaped/has_introducerare module-internal → ok - tests run locally:
cargo test --locked -p ssh-manager-core --lib ai::→ 212 passed (executed);terminal_escapes→ 23 passed (executed) - CI: all checks green on the head (executed:
gh pr checks 1606) - files read: 5/5 logic files (
terminal_escapes.rsin full, plusredactor.rs,live_redaction.rs,mod.rsandredactor_property.rsin the diff) - UI: not a UI change
- data: not touched
Timing analysis
- 2 test files analysed (
terminal_escapes.rs,live_redaction.rs;redactor_property.rsonly has a doc comment changed): no timing dependency found. The proptests use 300 cases with shared read-onlyLazyLockredactors.
Spec
- visible behaviour changed: escape sequences are removed from the forwarded output (SGR/erase without a trace, any other sequence becomes one space); with an escape introducer, masking is the union of the raw and stripped views
- spec searched (
rg -il 'escape|redact|maskier' docs/specs/); spec covering it: 0068 Part 1 - verdict: spec change present and matches the code. The sentence "Text ohne ESC bleibt unverändert" will also hold for invalid UTF-8 once finding 1 is fixed.
Security checks
- Loosening, compared with the base for
redact_bytes: the raw view runs the same rules in the same order on the decoded text, and its matches are mapped onto the stripped text and masked there, so by construction nothing is masked less than in the raw view. The only difference from the base decode is the U+FFFD count and how a raw 0x9B is represented (finding 1); I found no input for which that loses a match. - Bypass attempts (executed):
ESC SP,ESC (,ESC [+ letter,ESC[31;,ESC[, bare0x9B, OSC with BEL, OSC 8 with ST, DCS, SGR inside a key (pass\x1b[0mword=), and non-SGR escapes inside a token. Every secret the reference masks stays masked, and the output never contains ESC. - Fail-open: none. There is no error path, and an empty match carries no range and is filtered out.
- Threat model: the note "no change" holds (no new boundary or data flow), but its wording is outdated (see blocking finding 3).
Previous findings (follow-up round only)
- incomplete sequence before a secret leaks → fixed in ae4f32b (union of the raw and stripped views, as decided)
- U+E000 without ESC becomes a space → fixed in ae4f32b (fast path); new related finding 1 for invalid UTF-8
Follow-ups
None.
…osition escape tests (#1605) Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
Review points: 1. fixed in this push (decode: one U+FFFD per invalid sequence + regression test). 2. fixed (exact outputs for all cases). 3. fixed (random-position property added; PR body corrected). |
There was a problem hiding this comment.
Review
Verdict: changes requested
Review level: elevated
Blocking
crates/core/src/ai/terminal_escapes.rs:606-650(escapes_at_random_positions_never_leak): the property does not cover the maintainer's criterion "arbitrary escape sequences inserted anywhere". The test only allows insertion slots inside a secret, right after it, or at the end. It leaves out the position right before a secret and every position in the context words (account,password,-b, separators). It also compares with the reference run on the plain text. Insertions inside a secret add nothing, because thetext.contains(secret)filter then skips that secret. So in practice the property only checks escapes after a secret.any_escape_never_leaks_what_reference_maskscovers "in front of the secret" with one fixed pair, but no test inserts escapes into the context. The implementation does meet the criterion: I ran a temporary property (3,000 cases, about 2 s) that inserts 1–5any_escape()values atp % (len+1)with no position filter, runs the frozen reference on the same escaped input, and asserts that no literal secret the reference masks remains in the output (plus noESCin the output). It passed. Fix: replace the position filter with exactly that, i.e. any slot andReferenceTrait::redact_text(&*REFERENCE, &text)on the escaped text. Also remove the comment "an escape right before it is a known gap, see the PR … An escape swallows a following character". It points to the PR instead of describing the rule, and with the same-input reference it no longer applies.
Non-blocking
- None beyond the follow-up below.
Verified
- delta round: only
crates/core/src/ai/terminal_escapes.rschanged since 7a2a34f (read: full diff 7a2a34f..ef1d02b; production part of the file read again). files read: 1/1 logic files in the delta - counter-proof:
test_decode_matches_lossy_without_escapeis red with the old per-byte U+FFFD decoding ("abc�� def"vs"abc� def") and green with the fix (executed: temporary edit ofdecode,cargo test -p ssh-manager-core --lib test_decode_matches_lossy_without_escape, reverted,git statusclean) - edge cases:
\x9b\x9b→ two separate chunks, each a C1 introducer;\xE2\x9B+ non-continuation → one U+FFFD, the same asfrom_utf8_lossyand the base (read:decode,utf8_chunkssemantics); text without an introducer takesdecode+ the unchanged rule loop, so it is byte-for-byte the base (read) - exact-output tests for the eight incomplete-sequence inputs now assert the full strings (read)
- criterion-faithful property, escapes anywhere vs. reference on the same input: 3,000 cases, no leak (executed: temporary test, reverted)
- all
terminal_escapesproperties at 3,000 cases each: 26 passed (executed: temporarywith_cases(3000), reverted) - tests run locally:
cargo test --locked -q -p ssh-manager-core --lib ai::→ 214 passed (executed) - CI: all checks green on ef1d02b (executed:
gh pr checks 1606) - UI: not a UI change
- data: not touched
Timing analysis
- 1 test file analysed (delta:
terminal_escapes.rstests): no timing dependency found. 300-case proptests withLazyLockredactors are far below the per-test limit (possible, runtime only → non-blocking, no action needed).
Spec
- visible behaviour changed in this delta: none (decoding now matches the base again)
- spec searched (
rg -il 'escape|ANSI|Steuersequenz|redact' docs/specs/), spec covering it: 0068 Part 1 (escape and union rules, unchanged since the last round, matches the code) - verdict: spec change present and matches the code; changelog fragment present
Security checks
- loosening (delta):
decodenow emits one U+FFFD per invalid sequence, like the basefrom_utf8_lossy. The raw view and the no-escape fast path are therefore identical to the base again. No pattern sees fewer replacement characters than before. - bypass attempts:
\x9b\x9b,\xE2\x9B,\xF0\x9B,\xC3\x9B(valid U+00DB), invalid bytes next to ESC. None changes the introducer detection compared with the reviewed design. - Threat model: the PR body note now describes the union design; no new boundary.
Previous findings (follow-up round only)
- decode U+FFFD per byte → fixed in ef1d02b (regression test with counter-proof)
- incomplete-sequence test only checked needles → fixed in ef1d02b (exact outputs)
- random-position property → added, but narrowed (see Blocking)
- PR body (stale test name, Summary, threat-model note) → fixed
Follow-ups
- A non-SGR escape directly in front of a value (
AccountKey=ESC<value>) becomes a space, so the stripped view does not match where plain text would. The raw view keeps it no worse than the base. This is already listed in the PR, and the issue already hasfollow-up-pending.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
Review point 1: fixed — |
There was a problem hiding this comment.
Review
Verdict: approved
Review level: elevated
Blocking
- None.
Non-blocking
- PR body, "Follow-ups" and "Tests": they still say the random-position property "does not insert escapes right before a secret or inside non-secret context words" / "inside/after secrets". Since 933f77a the property uses every slot. The
AccountKey=ESC<value>gap described there is covered by the union with the raw view; the property now checks this case against the reference on the same input, and it passes. Please correct the text when you next touch the PR.
Verified
- Follow-up round: the delta ef1d02b..933f77a touches only the test module of
crates/core/src/ai/terminal_escapes.rs(read: full diff). files read: 1/1 logic files in the delta. The earlier rounds read all of the PR's files in full. - previous finding fixed:
escapes_at_random_positions_never_leaknow picks from every slot0..=lenand runs the frozen reference on the same escapedtext. The "known gap" comment is removed (read: terminal_escapes.rs:606-636). - counter-proof: with the raw-view union disabled (
maskedforced to false at terminal_escapes.rs:166),escapes_at_random_positions_never_leakfails with a minimal failing input. Aftergit checkout --it passes again (executed:cargo test -q -p ssh-manager-core escapes_at_random_positions_never_leak). The tree was clean afterwards. - tests run locally:
cargo test --locked -q -p ssh-manager-core ai::→ 214 passed (executed);ai::terminal_escapes→ 25 passed in 0.84 s (executed). - run time: the
ai::suite takes about 65 s on both this branch and the baserelease/0.8.0(188 passed, executed), so the PR does not cause it. - CI: every check is green on head 933f77a (executed:
gh pr checks 1606,gh run view … headSha). The PR is mergeable with the base. - edge cases: escapes before a secret, inside context words and inside secrets → covered by the property (secrets that are cut apart are filtered out as not literally present, as requested).
- callers checked: no production code changed in this delta.
- UI: not a UI change.
- data: not touched.
Timing analysis
- 3 test files analysed (terminal_escapes.rs, redactor_property.rs, live_redaction.rs): no race, wall-clock or ordering dependency found. One
possiblefinding (proptest run time under load, terminal_escapes.rs:585-680) → non-blocking: measured at 0.84 s for all 25 tests, far below the slow-timeout.
Spec
- visible behaviour changed in this delta: none (test only).
- spec searched in earlier rounds (
rg -il 'escape|ANSI|redact' docs/specs/); spec covering it: 0068 Part 1, updated in this PR. - verdict: spec change present and matches the code (checked in the previous round; unchanged since).
Security checks
- elevated (redaction). The delta only strengthens a test; no production check changed. The property now proves "never less than the reference" for escapes at any position, and the counter-proof shows it detects a missing raw-view union.
Previous findings (follow-up round only)
- random-position property did not insert escapes anywhere / compared against reference on plain text → fixed in 933f77a
- "known gap, see the PR" comment → removed in 933f77a
Follow-ups
- None new (the issue already carries
follow-up-pendingfrom earlier rounds).
Closes #1605
Summary
redact_bytesnow removes terminal escape sequences (CSI incl.ESC[K/SGR and 8-bit0x9B, OSC/DCS/SOS/PM/APC strings, otherESCsequences, loneESC; unterminated ones up to the end) and masks the union of the patterns on the raw text and on the stripped text (see Assumptions). One place, soredact,redact_text,LiveOutputRedactorand diagnostics all benefit. A sequence never swallows a line break, so live line-based release and its prefix/never-revise rules are unchanged; escape sequences are never split across a release because only whole lines are released.Acceptance Criteria
--color=alwaysoutput masked: met —terminal_escapes.rs:test_grep_color_password_value_is_maskedtest_pem_header_with_sgr_masks_the_bodytest_sgr_around_secret_leaves_exact_placeholdertest_key_and_value_coloured_separately_is_maskedESC[K, lone ESC, unterminatedESC[, C10x9Bremoved; plain text unchanged: met —test_osc_with_bel_and_st_is_removed,test_lone_esc_and_two_byte_sequences_are_removed,test_unterminated_sequences_are_removed_to_the_end,test_c1_csi_is_removed_raw_and_encoded,test_plain_text_is_unchangedcoloured_secret_is_still_redacted(asserts for secrets the redactor masks in plain text; some low-entropy generated values, e.g.sk-aaaa…, are not masked even without escapes — pre-existing)live_redaction.rs:test_coloured_secret_across_chunks_is_never_shown_nor_half_escape(every chunk size)redactor_propertypasses: met — generated documents contain no escapes, so both sides see identical text (documented in the test header)cargo test -p ssh-manager-core --lib ai::)Tests
terminal_escapestests: exact outputs for the space rule (test_lone_esc_and_two_byte_sequences_are_removed, OSC/ST,ESC[2~,ESC[@, C1),test_non_sgr_escapes_before_secrets_do_not_leak(exact outputs for the seven leaking inputs),test_non_sgr_escape_inside_secret_value_does_not_cut_it(exact outputs for escapes inside a value), propertyany_escape_never_leaks_what_reference_masks(arbitrary escapes wrapped around every generated secret never leave a secret the frozen reference masks), plus the SGR exact-output tests andsgr_wrapped_equals_plainunchanged. The redactors in these tests are now built once (LazyLock); theai::suite runs in ~75 s total. New:test_incomplete_sequence_before_secret_leaks_nothing(the eight inputs from the last review:ESC SP,ESC (,ESC [,ESC[31;,ESC[, bare0x9B),test_private_use_characters_without_escape_are_unchanged, and the property now also inserts incomplete sequences anywhere and no longer assumes awayESC [/ESC ]leads. Review round:decodeemits one U+FFFD per invalid sequence (test_decode_matches_lossy_without_escape, compared withfrom_utf8_lossy);test_incomplete_sequence_before_secret_leaks_nothingasserts the full output of every case; new propertyescapes_at_random_positions_never_leakinserts escapes at random positions inside/after secrets. Counter-proof: with the union disabled (stripped view only) the incomplete-sequence test, the inside-value test and the property fail. clippy clean.Assumptions
m) and erase (K) are removed without a trace; every other sequence (CSI with another final byte, OSC/DCS/SOS/PM/APC, two-byteESCsequences, a loneESCor0x9B) becomes exactly one space and never consumes the following character.\n/\r; an unterminated one yields one space.0x9Bthat is not valid UTF-8 is treated as C1 CSI.ESC/0x9Btakes the plain path, byte for byte as before (so U+E000 and other private-use characters stay). With an introducer, the output masks the union of the patterns on the raw text and on the stripped text; raw matches are mapped onto the stripped text with a per-byte offset map (no sentinel), and a raw match touching part of a removed sequence masks the whole stripped span it touches. Consequence: where an escape sits inside a URL/value, the raw view may mask a larger span than the stripped view alone (e.g.https://user:ESC[2~pass@hostbecomes[REDACTED]).Spec
updated 0068 (Part 1: space rule described).
Threat model: no change – the redactor still runs before text leaves; it now masks the union of the raw-text and stripped-text views (never less than before), so no boundary or data flow is added.
Manual test steps
None needed.
Follow-ups
AccountKey=ESC<value>) becomes a space and can defeat key=value patterns that need no gap; the random-position property therefore does not insert escapes right before a secret or inside non-secret context words.🤖 Generated with Claude Code